<template>
  <a-modal
        :title="title"
        :width="560"
        :visible="visible"
        :body-style="{paddingBottom: '100px'}"
		:dialogStyle="{top:'50px'}"
		:maskClosable="false"
       @ok="onOk"
       @cancel="onCancel"
  >
	<a-form-model ref="liForm" :model="form" :label-col="labelCol" :wrapper-col="wrapperCol" :rules="rules">
		<a-form-model-item label="id" v-show="false">
		  <a-input v-model="form.id" />
		</a-form-model-item>
				<a-form-model-item label="退休干部" prop="leaderInfoId" >
				  <a-select
				      show-search
				      v-model="form.leaderInfoId"
				      placeholder="请输入干部编号/姓名"
				      :default-active-first-option="false"
				      :show-arrow="false"
				      :filter-option="false"
				      :not-found-content="null"
				      @search="handleSearch"
				      @change="handleChange"
				    >
				      <a-select-option v-for="obj in leaderdata" :value="obj.id" :key="obj.id">
				       {{ obj.code }} - {{ obj.name }}
				      </a-select-option>
				    </a-select>
				</a-form-model-item>
				<a-form-model-item label="退休类型" prop="type" >
				  <a-select v-model="form.type" placeholder="请输入退休类型">
				    <a-select-option  v-for="(obj, index) in typedata" :key="index" :value="obj.name">{{obj.name}}</a-select-option>
				  </a-select>
				</a-form-model-item>
				<a-form-model-item label="退休时间" prop="retirementDate">
					<a-date-picker v-model="form.retirementDate" valueFormat="YYYY-MM-DD" placeholder="请输入退休时间" :style="{width:'100%'}"/>
				</a-form-model-item>
		</a-form-model>
  </a-modal>
</template>

<script>
import {getUrl} from '@/api/manage'
export default {
  components:{
   
  },
  name:"RetirementInfoFrom",
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    loading: {
      type: Boolean,
      default: () => false
    },
    model: {
      type: Object,
      default: () => null
    },
    title: {
      type: String,
      default : ''
    }
  },
  data () {
    return {
      labelCol: { span: 4 },
      wrapperCol: { span:20 },
	  selecetPosition : triggerNode => {return triggerNode.parentNode || document.body;},
      form: {
          id:'',
          leaderInfoId: undefined,
          type: undefined,
          retirementDate: ''
         
      },
	  leaderdata:[],
	  typedata:[],
      rules: {
        leaderInfoId: [
          {required: true, message: '退休干部不能为空', trigger: 'change' },
         
        ],
        type: [
          {required: true, message: '退休类型不能为空', trigger: 'blur' },
          
        ],
        retirementDate: [
          {required: true, message: '退休时间不能为空', trigger: 'change' },
          
        ]
      },
    }
  },
  created () {
    // 当 model 发生改变时，为表单设置值
    this.$watch('model', () => {
      Object.assign(this.form, this.model)
    })
  },
  methods: {
	fetch(value){
		var _this = this
		getUrl('leaderInfo/listbyname', {name:value})
		  .then(res => {
		    console.log(res)
		    _this.leaderdata = res.result
		})
	},
	handleSearch(value) {
		this.fetch(value);
	},
	handleChange(value) {
		console.log(value);
		this.value = value;
		this.fetch(value);
	},
    onCancel() {
       this.$emit("cancel",this)
    },
    onOk() {
       this.$emit("ok",this)
    }
  }
}
</script>
<style>
</style>
